<include file="__PUBLIC__/_header" />
<link href="__APP_SKIN__js/uploadify/uploadify.css?2" rel="stylesheet" type="text/css" />
<link href="__SKIN__/bootstrap-3.3.7/bootstrap-datetimepicker/css/bootstrap-datetimepicker.min.css" rel="stylesheet" media="screen">
<div class="main-container" id="main-container">

     <div class="main-content" style="margin-left: 0;">
            <div class="page-content">
                <!-- /.page-header -->
                <div class="row">
                    <div class="col-xs-12">
                        <div class="row">
                            <div class="col-sm-12">
                                <form class="form-horizontal" id="myform" role="form"  method="post" name="edit-form" >
                                    <table id="data-table" class="table table-bordered table-hover definewidth m10" >
                                        <tbody>
                                        <tr>
                                            <th width="10%">商品货号</th>
                                            <td>
                                               <input type="text" name="item_no"><b id="search_item">选择商品</b>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td id="result" colspan="2"></td>
                                        </tr>
                                        <tr>
                                            <th width="10%">菜品描述</th>
                                            <td>
                                                <input type="text" name="desc">
                                            </td>
                                        </tr>
                                        <tr>
                                            <th width="10%">促销价格</th>
                                            <td>
                                                <input type="text" name="price">
                                            </td>
                                        </tr>
                                        <tr>
                                            <th width="10%">状态</th>
                                            <td>
                                                <select name="state">
                                                    <option value="1">上架</option>
                                                    <option value="0">下架</option>
                                                </select>
                                            </td>
                                        </tr>
                                        <tr>
                                            <th width="10%">最迟配送时间</th>
                                            <td>
                                                <input type="text" class="text-center  field-edit type6" placeholder="有效时间" data-m="" data-id="m_deliver_limit_time" name="m_deliver_limit_time" id="m_deliver_limit_time" value="">
                                            </td>
                                        </tr>
                                        <tr>
                                            <th width="10%">类别</th>
                                            <td>

                                                <select name="kind_id">
                                                    <volist name="kinds" id="vo">
                                                        <option value="{$vo.id}">{$vo.title}</option>
                                                    </volist>
                                                </select>
                                            </td>
                                        </tr>
                                        </tbody>
                                        <tfoot>
                                        <tr>
                                            <td colspan="13">
                                                <button class="btn btn-info" type="button" id="base_submit"> <i class="icon-ok bigger-110"></i> 确定 </button>
                                            </td>
                                        </tr>
                                        </tfoot>
                                    </table>
                                </form>
                            </div>
							
                            <!-- /span -->
                        </div>
                        <!-- /row -->
                    </div>
                    <!-- PAGE CONTENT ENDS -->
                </div>
                <!-- /.row -->
            </div>
        </div>
    </div>
</div>
<input type="hidden" id="update_img" value="{$arr['img']}">
<input type="hidden" id="uploadSwf" value="__APP_SKIN__js/uploadify/uploadify.swf">
<input type="hidden" id="uploader" value="{:Controller::createUrl('vis/file/index')}">
<input type="hidden" id="service_url" value="{:Controller::getConfig('file_server_url')}">

<script src="__APP_SKIN__js/jquery-2.0.3.min.js"></script>
<script src="__APP_SKIN__js/bootstrap.min.js"></script>
<script src="__APP_SKIN__js/uploadify/jquery.uploadify.js?12" type="text/javascript"></script>
<script>

    function chk_form(){

        if($('input[name=item_no]').val() =='' || $('input[name=item_no]').val() ==''){
            $('input[name=item_no]').focus();
            $('input[name=item_no]').html('商品货号或空');
            return false;
        }
        if($('input[name=price]').val() =='' || $('input[name=price]').val() ==''){
            $('input[name=price]').focus();
            $('input[name=price]').html('促销价格0或空');
            return false;
        }
    }
    $(function () {
        $("#base_submit").click(function(){
            $.ajax({
                //几个参数需要注意一下
                type: "POST",//方法类型
                dataType: "json",//预期服务器返回的数据类型
                url:"{:Controller::_createUrl('promotion/add')}",
                data: $('#myform').serialize(),
                success: function (result) {
                    console.log(result);//打印服务端返回的数据(调试用)
                    if (result.code == 200) {
                        window.parent.location.reload();
                    }else{
                        alert('添加失败');
                    }
                },
                error : function() {
                    return false;
                }
            });
        });

        $("#search_item").click(function(){
            var keyword = $("input[name=item_no]").val();
            var search_type = $("select[name=search_type]").val();
            $.ajax({
                type:"POST",
                async:false,
                dataType:"json",
                url:"{:Controller::_createUrl('promotion/searchItem')}",
                data:{keyword:keyword,search_type:search_type},
                success:function(data,textStatus){
                    $("#result").show();
                    var html = '';
                    $("#result").html("");
                    for (var i=0;i<data.data.list.length;i++){
                        html += '<p style="float: left;width: 150px;margin: 10px;" data-id="'+data.data.list[i].m_id+'"><label class="uname">' +data.data.list[i].m_name+"["+data.data.list[i].bar_code+"]"+
                                '</label><labe class="uck"l><input name="item_no_chk" value="'+data.data.list[i].bar_code+'" type="radio"/></label></p>';
                    }
                    $("#result").append(html);
                    $("input[name=item_no_chk]").click(function(){
                        $("input[name=item_no]").val($(this).val());
                        $("#result").hide();
                    })
                },
                error:function(XMLHttpRequest,textStatus,errorThrown){
                    bootbox.dialog({
                        message: "<span class='btn-sm btn-danger'>网络错误！</span>"
                    });
                }
            });
        })
    })
</script>
<script type="text/javascript" src="__SKIN__/bootstrap-3.3.7/bootstrap-datetimepicker/js/bootstrap-datetimepicker.min.js" charset="UTF-8"></script>
<script type="text/javascript" src="__SKIN__/bootstrap-3.3.7/bootstrap-datetimepicker/js/locales/bootstrap-datetimepicker.zh-CN.js" charset="UTF-8"></script>
<script src="__SKIN__/bootstrap-3.3.7/js/jquery.spinner.min.js"></script>
<script type="text/javascript">
    $('.type6').datetimepicker({
        language:  'zh-CN',
        format: 'yyyy-mm-dd H:i:s',
        weekStart: 1,
        todayBtn:  1,
        autoclose: 1,
        todayHighlight: 1,
        startView: 2,
        minView: 2,
        forceParse: 0
    });
</script>
</body>
</html>